﻿var TodoBiz4MiniTop = function (rHd) {
    var __hd = (typeof (rHd) == "string") ? rHd : "todoBiz4MiniTop";
    var __todoData = null;
    var __ajax = null;
    var __listBox = null;
    var __requestUrl = null;
    var __detailBox = null;
    var __detailBoxId = null;

    var __loadingBox = null;
    var __loadingBoxId = null;
    var __formBox = null;
    var __formBoxId = null;
    var __currentOperatorId = null;
    var __itemSelectorHd = null;
    var __userSelectorHd = null;
    var __userId = null;
    var __datetime = new Date();
    var __datePanel = null;
    var __jc = new JskitCalendar();

    var __msgFunc = function (rContent) {
        rContent = rContent.replace(/\$n/gi, "<br/>");
        jskitBulter.msg.show({
            "Title": "INFO",
            "Content": rContent,
            "RefUrl": null,
            "Redirect": null,
            "Mode": "alert",
            "CallBack": null
        });
    };
    var __dtStr2Short = function (rDtStr) {
        var _dt = jskitUtil.date.parse(rDtStr);
        if (_dt != null) {
            return _dt.toString("yyyy-MM-dd");
        } else {
            return "";
        }
    };
    /* BEGIN: 函数 -------------------------------*/

    var __costHours = function (rDtStr1, rDtStr2) {
        var dt1 = jskitUtil.date.parse(rDtStr1);
        var dt2 = jskitUtil.date.parse(rDtStr2);
        var minutes = (dt2.getTime() - dt1.getTime()) / (1000 * 60);
        var hours = Math.floor(minutes / 60);
        var mod = minutes % 60;
        if (mod >= 15 && mod <= 45) {
            hours += 0.5;
        } else if (mod > 45) {
            hours += 1;
        }
        return hours;
    };

    var __popupBrowser = function () {
        if (window.external != null) {
            window.external.FrmShow();
        }
    };
    /* END: 函数 -------------------------------*/

    /* BEGIN: 处理TODO相关 ---------------------*/
    var __startLoading = function () {
        if (__loadingBox == null) {
            __loadingBox = $("#" + __loadingBoxId);
        }
        __loadingBox.innerHTML = "数据加载中...";
        __loadingBox.style.display = "";
    };
    var __endLoading = function () {
        if (__loadingBox == null) {
            __loadingBox = $("#" + __loadingBoxId);
        }
        __loadingBox.innerHTML = "";
        __loadingBox.style.display = "none";
    };

    var __loadData = function () {
        __startLoading();
        __requestUrl = "Ws/_Todo.aspx?act=0&dt=" + __datetime.toString("yyyy-MM-dd");
        __ajax = new JskitXmlHttpAction(__requestUrl + "&rm=" + jskitUtil.guid(), __hd + ".__loadDataCallback", "text");
    };
    this.__loadDataCallback = function (json) {
        __ajax = null;
        __endLoading();
        try {
            eval("__todoData = " + json + ";");
        } catch (e) {
            __msgFunc("Load Data Exception:" + e.message);
            return;
        }
        if (__todoData[0] == 0) {
            __msgFunc(__todoData[1]);
            return;
        }
        __buildList();
    };
    var __buildList = function () {
        var _str = new Array();
        var _item = null;
        var _sum = 0;
        var _cost = 0;
        var _group = new Array();
        _group.push({ key: "", title: "其他", data: "", cost: 0 });
        var _groupStr = new Array();
        var _groupTitle = null;
        var _groupExists = false;
        for (var i = 0; i < __todoData.length; i++) {
            _groupStr = new Array();
            _groupTitle = "";
            _item = __todoData[i];
            _cost = (isNaN(parseFloat(_item.CostHours))) ? 0 : parseFloat(_item.CostHours);
            _sum += _cost;
            _groupStr.push('<div class="todo_item" id="todo_item_' + i + '" ondblclick="' + __hd + '.ShowDetails(' + i + ')">');

            _groupStr.push('<div class="title">');
            if (_item.IsLocked == '1') {
                _groupStr.push('<div class="icon_locked"></div>');
            } else {
                _groupStr.push('<img src="/cellula_client/default/calendar/images/sign_' + _item.TodoLevel + '.png" width="16px" height="16px" alt="' + _item.LevelName + '" align="absmiddle" />');
            }
            //_str.push((i + 1) + '.');
            _groupStr.push('<a href="javascript:' + __hd + '.ShowDetails(' + i + ')">' + _item.TodoTitle + '</a>');
            if (_item.IsPrivate == "1") {
                _groupStr.push('<sup>P</sup>');
            }
            _groupStr.push('</div>');

            _groupStr.push('<div class="typeinfo">');
            _groupStr.push('<p>');
            _groupStr.push(_item.TypeName);
            if (_item.Operator != _item.AssignToUser) {
                _groupStr.push('，来自 ' + _item.OperatorName);
            }
            _groupStr.push('，' + _item.CostHours + 'H');
            _groupStr.push('</p>');
            _groupStr.push('</div>');


            _groupStr.push('<div class="action">');
            if (_item.IsLocked == "1") {//locked ,do nothing
                _groupStr.push('<button class="btn_update0" disabled="disabled" title="更新">&nbsp;</button>');
                _groupStr.push('<button class="btn_delete0" disabled="disabled" title="删除">&nbsp;</button>');
                _groupStr.push('<button class="btn_start0" disabled="disabled" title="开始">&nbsp;</button>');
                _groupStr.push('<button class="btn_finish0" disabled="disabled" title="完成">&nbsp;</button>');
            } else {
                _groupStr.push('<button class="btn_update" onclick="' + __hd + '.updateTask(' + i + ')" title="更新">&nbsp;</button>');
                if (__userId == _item.Operator) {//self
                    _groupStr.push('<button class="btn_delete" onclick="' + __hd + '.deleteTask(' + i + ')" title="删除">&nbsp;</button>');
                } else {
                    _groupStr.push('<button class="btn_delete0" disabled="disabled" title="删除">&nbsp;</button>');
                }
                if (_item.StartToReal == "") {//未开始
                    _groupStr.push('<button class="btn_start" onclick="' + __hd + '.StartTaskAction(' + i + ')" title="开始">&nbsp;</button>');
                    _groupStr.push('<button class="btn_finish0" disabled="disabled" title="完成">&nbsp;</button>');
                } else {//已经开始
                    _groupStr.push('<button class="btn_start0" disabled="disabled" title="开始">&nbsp;</div>');
                    if (_item.IfClose == 0) {
                        _groupStr.push('<button class="btn_finish" onclick="' + __hd + '.CloseTaskAction(' + i + ')" title="完成">&nbsp;</button>');
                    } else {
                        _groupStr.push('<button class="btn_finish0" disabled="disabled" title="完成">&nbsp;</button>');
                    }
                }
            }
            _groupStr.push('</div>');

            _groupStr.push('</div>');
            /*-------------------------------------*/
            _groupExists = false;
            for (var j = 0; j < _group.length; j++) {
                if (_group[j].key == _item.RefItemKey) {
                    _group[j].data += _groupStr.join('');
                    _group[j].cost += parseFloat(_item.CostHours);
                    _groupExists = true;
                    break;
                }
            }
            if (!_groupExists) {
                _group.push({ key: _item.RefItemKey, title: _item.RefItemName, data: _groupStr.join(''), cost: parseFloat(_item.CostHours) });
            }
            /*-------------------------------------*/
        } //for end
        _str.push('<div class="bbody">');
        if (__todoData.length > 0) {
            for (var i = _group.length - 1; i >= 0; i--) {
                if (_group[i].data == '') { continue; }
                _str.push('<div class="group_title">' + _group[i].title + ',' + _group[i].cost + 'H</div>');
                _str.push(_group[i].data);
            }
        } else {
            _str.push('<div class="empty">这个家伙很懒，' + __datetime.toString("M月d日") + '这天啥也没记录！</div>');
        }
        _str.push('</div>');
        _group = _groupStr = _groupTitle = _groupExists = null;

        var _str2 = new Array();
        _str2.push('<div class="todo_total_info">');
        _str2.push('<div class="info">共 <span>' + __todoData.length + '</span> 个任务 ，耗时 <span>' + _sum + '</span> 小时</div>');
        _str2.push('<div class="btn_addtask" onclick="jBiz.addTask(null);">增加任务</div>');
        _str2.push('</div>');
        _item = _sum = _cost = null;
        __listBox.innerHTML = _str2.join('') + _str.join('');
        _str = _str2 = null;
    };

    var __showContentInDetailsBox = function (rContent) {
        if (__detailBox == null) {
            __detailBox = $("#" + __detailBoxId);
        }
        if (__detailBox == null) {
            __msgFunc("Details box not found!");
            return;
        }
        __detailBox.innerHTML = rContent;
        __detailBox.className = "detial_box_open";
        __detailBox.style.display = "";
    };
    this.ShowDetails = function (idx) {
        var _eo = __todoData[idx];
        var _str = new Array();
        _str.push('<div class="action" onclick="' + __hd + '.CloseDetails()">[关闭]</div>');
        _str.push('<div class="title">' + _eo.TodoTitle + '</div>');
        _str.push('<div class="info">');
        _str.push('<div>类型：' + _eo.TypeName + '</div>');
        if (_eo.RefItemName != "") {
            _str.push('<div>项目：' + _eo.RefItemName + '</div>');
        } else {
            _str.push('<div>项目：未关联</div>');
        }
        if (_eo.Operator != _eo.AssignToUser) {
            _str.push('<div>来自：' + _eo.OperatorName + '</div>');
        } else {
            _str.push('<div>来自：自己</div>');
        }
        _str.push('<div>耗时：' + _eo.CostHours + ' 小时</div>');
        _str.push('<div>计划：' + _eo.StartToPlan + ' - ' + _eo.EndToPlan + '</div>');
        _str.push('<div>实际：' + _eo.StartToReal + ' - ' + _eo.EndToReal + '</div>');
        _str.push('</div>');
        _str.push('<div class="bbody">');
        if (_eo.Content == '') {
            _str.push('<div>内容：无</div>');
        } else {
            _str.push('<div>内容：' + _eo.Content + '</div>');
        }
        _str.push('</div>');

        __showContentInDetailsBox(_str.join(''));
        _str = null;
    };
    this.CloseDetails = function () {
        __detailBox.innerHTML = "";
        __detailBox.className = "detial_box";
        __detailBox.style.display = "none";
    };
    this.StartTaskAction = function (idx) {
        if (confirm("确定要开始该任务？")) {
            __startLoading();
            __ajax = new JskitXmlHttpAction("Ws/_Todo.aspx?act=10&id=" + __todoData[idx].TodoKey, __hd + ".StartTaskCallback", "text");
        }
    };
    this.CloseTaskAction = function (idx) {
        if (confirm("确定该任务已完成或终止？")) {
            __startLoading();
            __ajax = new JskitXmlHttpAction("Ws/_Todo.aspx?act=11&id=" + __todoData[idx].TodoKey, __hd + ".CloseTaskCallback", "text");
        }
    };
    this.StartTaskCallback = function (json) {
        __endLoading();
        __ajax = null;
        try {
            eval("var _bk = " + json + ";");
        } catch (e) {
            __msgFunc(e.message);
            return;
        }
        if (_bk[0] == "0") {
            __msgFunc(_bk[1]);
        } else {
            __loadData();
        }
    };
    this.CloseTaskCallback = function (json) {
        __endLoading();
        __ajax = null;
        try {
            eval("var _bk = " + json + ";");
        } catch (e) {
            __msgFunc(e.message);
            return;
        }
        if (_bk[0] == "0") {
            __msgFunc(_bk[1]);
        } else {
            __loadData();
        }
    };
    this.addTask = function () {
        __showTaskForm(null);
    };
    this.updateTask = function (rIdx) {
        __showTaskForm(rIdx);
    };
    this.deleteTask = function (rIdx) {
        if (confirm("确定要删除该任务？")) {
            __deleteTask(rIdx);
        }
    };
    var __deleteTask = function (rIdx) {
        var _url = "Ws/_Todo.aspx?act=33&id=" + __todoData[rIdx].TodoKey + "&rm=" + jskitUtil.guid();
        __ajax = new JskitXmlHttpAction(_url, __hd + ".__deleteTaskCallback", "text");
        __startLoading();
    };
    this.__deleteTaskCallback = function (json) {
        __endLoading();
        __ajax = null;
        try {
            eval("var _bk = " + json + ";");
        } catch (e) {
            __msgFunc(e.message);
            return;
        }
        if (_bk[0] == "0") {
            __msgFunc(_bk[1]);
        } else {
            __loadData();
        }
    };
    var __showTaskForm = function (rIdx) {
        if (rIdx != null) {
            $("#f_hid_idx").value = rIdx;
            $("#f_txt_Title").value = __todoData[rIdx].TodoTitle;
            var _dt = jskitUtil.date.parse(__todoData[rIdx].StartToReal);
            $("#f_txt_StartHour").value = (_dt != null) ? _dt.getHours() : "";
            $("#f_txt_StartMin").value = (_dt != null) ? _dt.getMinutes() : "";
            _dt = jskitUtil.date.parse(__todoData[rIdx].EndToReal);
            $("#f_txt_EndHour").value = (_dt != null) ? _dt.getHours() : "";
            $("#f_txt_EndMin").value = (_dt != null) ? _dt.getMinutes() : "";
            $("#f_ddl_type").value = __todoData[rIdx].TodoType;
            _dt = null;
            $("#f_txt_Content").value = __todoData[rIdx].Content;
            $("#f_txt_Item").value = __todoData[rIdx].RefItemName;
            $("#f_hid_ItemKey").value = __todoData[rIdx].RefItemKey;
            $("#f_txt_AssignTo").value = __todoData[rIdx].AssignToUserName;
            $("#f_hid_AssignTo").value = __todoData[rIdx].AssignToUser;
            $("#f_txt_Cost").value = __todoData[rIdx].CostHours;
            var _occdt = jskitUtil.date.parse(__todoData[rIdx].OccurDt);
            $("#f_txt_Occur").value = (_occdt == null) ? "" : _occdt.toString("yyyy-MM-dd");
            _occdt = null;
        } else {
            var _dt = (__datetime != null) ? __datetime : (new Date());
            $("#f_hid_idx").value = "";
            $("#f_txt_Title").value = "";
            $("#f_txt_StartHour").value = (new Date()).getHours();
            $("#f_txt_StartMin").value = 0;
            $("#f_txt_EndHour").value = "";
            $("#f_txt_EndMin").value = "";
            $("#f_txt_Content").value = "";
            $("#f_txt_Item").value = "";
            $("#f_hid_ItemKey").value = "";
            $("#f_txt_AssignTo").value = "";
            $("#f_hid_AssignTo").value = "";
            $("#f_txt_Cost").value = 1;
            $("#f_txt_Occur").value = _dt.toString("yyyy-MM-dd");
            _dt = null;
        }
        __formBox.style.display = "";
    };
    this.taskFormSubmit = function () {
        var _idx = $("#f_hid_idx").value;
        var _url = "Ws/_Todo.aspx";
        if (_idx == "" || _idx == null) {
            _url += "?act=31";
        } else {
            _url += "?act=32&id=" + __todoData[_idx].TodoKey;
        }

        var _title = $("#f_txt_Title").value;
        if (_title == '') {
            alert("请输入标题");
            $("#f_txt_Title").focus();
            return;
        }
        var _occ = $("#f_txt_Occur").value;
        if (_occ == '') {
            alert("请输入日期");
            $("#f_txt_Occur").focus();
            return;
        }
        var _cost = $("#f_txt_Cost").value;
        if (_cost == '') {
            alert("请输入耗时");
            $("#f_txt_Cost").focus();
            return;
        }
        if (_min == '') { _min = 0; }
        _url += "&title=" + encodeURI(_title);
        _url += "&occ=" + encodeURI(_occ);
        _url += "&cost=" + encodeURI(_cost);
        _url += "&item=" + encodeURI($("#f_hid_ItemKey").value);
        _url += "&type=" + encodeURI($("#f_ddl_type").value);
        var _min = null;
        var _hour = null;
        if ($("#f_txt_StartHour").value != "") {
            _min = __fixMin($("#f_txt_StartMin").value);
            _hour = __fixMin($("#f_txt_StartHour").value);
            if (isNaN(_hour) || _min < 0 || _min > 59) { _min = 0; }
            var _start = jskitUtil.date.parse(_occ + " " + _hour + ":" + _min + ":0");
            if (_start != null) {
                _url += "&st=" + encodeURI(_start.toString("yyyy-MM-dd hh:mm:ss"));
            }
            _start = null;
        }
        if ($("#f_txt_EndHour").value != '') {
            _min = __fixMin($("#f_txt_EndMin").value);
            _hour = __fixMin($("#f_txt_EndHour").value);
            var _end = jskitUtil.date.parse(_occ + " " + _hour + ":" + _min + ":0");
            if (_end != null) {
                _url += "&et=" + encodeURI(_end.toString("yyyy-MM-dd hh:mm:ss"));
            }
            _end = null;
        }
        _min = _hour = null;
        _url += "&ato=" + encodeURI($("#f_hid_AssignTo").value);
        _url += "&content=" + encodeURI($("#f_txt_Content").value);
        __ajax = new JskitXmlHttpAction(_url, __hd + ".taskFormSubmitCallback", "text");
        __startLoading();
        _url = _start = _min = _idx = _title = _occ = _cost = null;
    };
    var __fixMin = function (v) {
        var _val = parseInt(v);
        if (isNaN(_val) || _val < 0 || _val > 59) { return 0; }
        else { return _val; }
    };
    var __fixHour = function (v) {
        var _val = parseInt(v);
        if (isNaN(_val) || _val < 0 || _val > 23) { return 0; }
        else { return _val; }
    };
    this.taskFormSubmitCallback = function (json) {
        __endLoading();
        __ajax = null;
        try {
            eval("var _bk = " + json + ";");
        } catch (e) {
            __msgFunc(e.message);
            return;
        }
        if (_bk[0] == "0") {
            __msgFunc(_bk[1]);
        } else {
            this.closeTaskForm();
            __loadData();
        }
    };
    this.closeTaskForm = function () {
        __formBox.style.display = "none";
    };
    var __initFormBox = function () {
        var _str = "";
        _str += '<div class="topaction" onclick="' + __hd + '.closeTaskForm()">关闭</div>';
        _str += '<input type="hidden" id="f_hid_idx" value="" />';
        _str += '<table>';
        _str += '<tr>';
        _str += '<th>*标题：</th>';
        _str += '<td><input type="text" size="34" id="f_txt_Title" value="" /></td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>*类型：</th>';
        _str += '<td>' + __todoTypeSelectCode("f_ddl_type", "") + '</td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>*相关项目：</th>';
        _str += '<td><input type="text" size="31" id="f_txt_Item" value="" /><inpu type="hidden" id="f_hid_ItemKey" value="" /></td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>*耗时：</th>';
        _str += '<td><input type="text" size="4" id="f_txt_Cost"  value="" /> 小时</td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>*日期：</th>';
        _str += '<td><input type="text" id="f_txt_Occur"  value="" onclick="jskitDateSelector.openMode(this,event,\'d\')"  /></td>';
        _str += '</tr>';
        /*
        _str += '<tr>';
        _str += '<th>计划开始：</th>';
        _str += '<td><input type="text" id="f_txt_StartToPlan"  value=""  onclick="jskitDateSelector.openMode(this,event,\'dt\')" /></td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>计划结束：</th>';
        _str += '<td><input type="text" id="f_txt_EndToPlan" value=""  onclick="jskitDateSelector.openMode(this,event,\'dt\')" /></td>';
        _str += '</tr>';
        _str += '<tr>';
        */
        _str += '<th>开始时间：</th>';
        _str += '<td><input type="text" size="2" maxlength="2" id="f_txt_StartHour" /> 时- <input type="text" size="2" maxlength="2" id="f_txt_StartMin"> 分</td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>结束时间：</th>';
        _str += '<td><input type="text" size="2" maxlength="2" id="f_txt_EndHour" /> 时- <input type="text" size="2" maxlength="2" id="f_txt_EndMin"> 分</td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>指派给：</th>';
        _str += '<td><input type="text" id="f_txt_AssignTo" size="31"   value=""  /><input type="hidden" id="f_hid_AssignTo"  value=""  /></td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>内容：</th>';
        _str += '<td><textarea id="f_txt_Content" rows="6" cols="27"></textarea></td>';
        _str += '</tr>';
        _str += '<tr>';
        _str += '<th>&nbsp;</th>';
        _str += '<td>';
        _str += '<input type="button" onclick="' + __hd + '.taskFormSubmit()" value="保存" />';
        _str += '<input type="button" onclick="' + __hd + '.closeTaskForm()" value="取消" />';
        _str += '</td>';
        _str += '</tr>';
        _str += '</table>';
        __formBox.innerHTML = _str;
        __itemSelectorHd.deploy("f_txt_Item", "f_hid_ItemKey", "Ws/_item.aspx?act=todo");
        __userSelectorHd.deploy("f_txt_AssignTo", "f_hid_AssignTo", "Ws/_User.aspx?mode=low");
        //jskitRichDropDownList.setDebugMode("yes");
        _str = _title = _startToPlan = _endToPlan = _startToReal = _itemName = _itemKey = _content = null;
    };
    var __todoTypeSelectCode = function (rId, rVal) {
        var _str = new Array();
        _str.push('<select id="' + rId + '" >');
        var _data = [["todo_daily", "日常工作"], ["todo_metting", "会议"], ["todo_officemanagement", "行政管理"], ["todo_biztrip", "商务旅行"], ["todo_holiday", "休假"], ["todo_other", "其他"]];
        for (i = 0; i < _data.length; i++) {
            if (i == rVal) {
                _str.push('<option value="' + _data[i][0] + '" selected="selected">' + _data[i][1] + '</option>');
            } else {
                _str.push('<option value="' + _data[i][0] + '">' + _data[i][1] + '</option>');
            }
        }
        _str.push('</select>');
        return _str.join('');
    };
    /* END: 处理TODO相关 ---------------------*/

    /* BEGIN: 处理 统计 相关 ---------------------*/
    var __statData = null;
    var __loadStatData = function () {
        __ajax = new JskitXmlHttpAction("Ws/_Todo.aspx?act=81&dt=" + __datetime.toString("yyyy-MM-dd"), __hd + ".__loadStatDataCallback", "text");
        __startLoading();
    };
    this.__loadStatDataCallback = function () {
        __ajax = null;
        __endLoading();
        try {
            eval("__statData = " + json + ";");
        } catch (e) {
            //alert(json);
            __msgFunc("Data Parsing Error:<br/>" + e.message);
            return;
        }
        if (__statData[0] == 0) {
            __msgFunc(__statData[1]);
            return;
        }
        __showStatList();
    };
    var __showStatList = function () {
        var _str = new Array();
        if (__statData == null) {
            _str.push("no data");
        } else {
            var _item = null;
            var _sum = 0;
            _str.push('<table cellspacing="0" cellpadding="0" class="manhour_gridview" >');
            _str.push('<thead>');
            _str.push('<tr><td></td><td>查看项</td><td></td><td>工时</td></tr>');
            _str.push('</thead>');
            _str.push('<tbody>');
            for (var i = 0; i < __statData.length; i++) {
                _item = __statData[i];
                _str.push('<tr>');
                _str.push('<td>' + (i + 1) + '</td>');
                _str.push('<td>' + _item.Key + '</td>');
                _str.push('<td>' + _item.Caption + '</td>');
                _str.push('<td>' + _item.Value + '</td>');
                _str.push('</tr>');
                _sum += parseFloat(_item.Value);
            }
            _str.push('</tbody>');
            _str.push('<tfoot>');
            _str.push('<tr><td colspan="3">合计</td><td>' + _sum + '</td></tr>');
            _str.push('</tfoot>');
            _str.push('</table>');
            _item = null;
        }
        __listBox.innerHTML = _str.join('');
        _str = null;
    };
    /* END: 处理 统计 相关 ---------------------*/

    /* BEGIN: 处理提醒 ---------------------*/
    var __alertIntervalMinutes = 5;
    var __alertTimer = null;
    var __alertMsgList = new Array();
    var __ALERT_MSG = function (rContent) {
        this.content = (typeof (rContent) == "string") ? rContent : "";
        this.read = false;
    };
    var __showAlertMsg = function () {
        if (__alertMsgList == null || __alertMsgList.length < 1) {
            return false;
        }
        var _str = new Array();
        for (var i = 0; i < __alertMsgList.length; i++) {
            _str.push('<div class="alert_item">' + __alertMsgList[i].content + '</div>');
        }
        __showContentInDetailsBox(_str.join(''));
        __popupBrowser();
        __alertMsgList = new Array();
        return true;
    };
    this.AlertCheck = function () {
        __checkMail();
        __checkTodo();
        __showAlertMsg();
    };
    this.setAlertInterval = function (v) {
        __alertIntervalMinutes = (isNaN(parseInt(v))) ? 5 : parseInt(v);
        if (__alertIntervalMinutes < 5 || __alertIntervalMinutes > 60) {
            __alertIntervalMinutes = 5;
        }
    };
    /* END: 处理提醒 ---------------------*/


    /* BEGIN: 检查站内信 ---------------------*/
    var __ajaxMail = null;
    var __checkMail = function () {
        var _url = "Ws/_Msg.aspx?mode=new";
        __ajaxMail = new JskitXmlHttpAction(url, __hd + ".__checkMailCallback", "text");
    };
    this.__checkMailCallback = function (json) {
        __ajaxMail = null;
        var _mailData = null;
        try {
            eval("_mailData = " + json + ";");
        } catch (e) {
            __msgFunc(e.message);
            return;
        }
        if (_mailData != null && _mailData.length > 0) {
            __alertMsgList.push(new __ALERT_MSG("您有[" + _mailData.length + "]封未读站内信"));
        }
    };
    /* END: 检查站内信 ---------------------*/
    /* BEGIN: 检查TODO时间 ---------------------*/
    var __checkTodo = function () {
        if (__todoData != null && __todoData.length > 0) {
            var _dt = new Date();
            var _eo = null;
            var _delay = null;
            for (var i = 0; i < __todoData.length; i++) {
                _eo = __todoData[i];
                if (_eo.EndToReal == "") {//未完成的任务
                    if (_eo.StartToReal == "") {//如果未启动，检查当前时间是否比计划启动时间小
                        _delay = jskitUtil.date.timeSpan(_eo.StartToPlan, _dt)["totalMinute"]
                        if (_delay > 0) {
                            __alertMsgList.push(new __ALERT_MSG("任务“" + _eo.TodoTitle + "”没有按计划启动，已延迟" + _deplay + "分钟"));
                        }
                    } else {//如果已启动，检查当前时间是否比计划完成时间大
                        _delay = jskitUtil.date.timeSpan(_eo.EndToPlan, _dt)["totalMinute"];
                        if (_delay > 0) {
                            __alertMsgList.push(new __ALERT_MSG("任务“" + _eo.TodoTitle + "”已延期" + _delay + "分钟"));
                        }
                    }
                }
            }
            _dt = _eo = _deplay = null;
        }
    };
    /* END: 检查TODO时间 ---------------------*/

    /* BEGIN: 跟踪Track -----------------------*/
    var __trackData = null;
    var __itemKey = null;
    this.setItem = function (v) {
        __itemKey = v;
    };
    var __loadTrackData = function () {
        var _url = "Ws/_Todo.aspx?act=81&dt=" + __datetime.toString("yyyy-MM-dd") + "&ik=" + __itemKey + "&rm=" + jskitUtil.guid();
        __ajax = new JskitXmlHttpAction(_url, __hd + ".__loadTrackDataCallback", "text");
        _url = null;
        __startLoading();
    };
    this.__loadTrackDataCallback = function (json) {
        __ajax = null;
        __endLoading();
        try {
            eval("__trackData = " + json + ";");
        } catch (e) {
            //alert(json);
            __msgFunc("Data Parsing Error:<br/>" + e.message);
            return;
        }
        if (__trackData[0] == 0) {
            __msgFunc(__trackData[1]);
            return;
        }
        __showTrackList();
    };
    var __showTrackList = function () {
        var _str = new Array();
        var _item = null;
        var _sum = 0;
        for (var i = 0; i < __trackData.length; i++) {
            _item = __trackData[i];
            _cost = (isNaN(parseFloat(_item.CostHours))) ? 0 : parseFloat(_item.CostHours);
            _sum += _cost;
            _str.push('<div class="track_item">');

            _str.push('<div class="title">');
            _str.push((i + 1) + "、");
            _str.push(_item.TodoTitle);
            _str.push('</div>');

            _str.push('<div class="info">');
            _str.push('<p>');
            _str.push(_item.UserName);
            _str.push('，' + _item.CostHours + 'H');
            _str.push('</p>');
            _str.push('</div>');

            _str.push('</div>');
        }
        __listBox.innerHTML = '<div class="sum">任务数：' + __trackData.length + '，工时合计：' + _sum + ' H</div><div class="bbody">' + _str.join('') + '</div>';
        _str = _item = _sum = null;
    };
    this.showTrackList = function () {
        __listBox.innerHTML = "";
        __loadTrackData();
    };
    /* END: 跟踪Track -------------------------*/

    /* BEGIN: 用户工时查看--------------------*/
    this.setUser = function (rUserKey) {
        __userId = (typeof (rUserKey) == "string") ? rUserKey : "";
    };
    this.switchUser = function (rUserKey, rUserName) {
        if (rUserKey == null || rUserKey == '') {
            $("#txt_user").value = "";
            $("#hid_user").value = "";
        } else {
            $("#txt_user").value = rUserName;
            $("#hid_user").value = rUserKey;
        }
        this.setUser(rUserKey);
        this.loadManhourList();
    };
    var __manHourData = null;
    var __loadUserManhour = function () {
        var _url = "Ws/_Todo.aspx?act=91&dt=" + __datetime.toString("yyyy-MM-dd") + "&uid=" + __userId + "&rm=" + jskitUtil.guid();
        __ajax = new JskitXmlHttpAction(_url, __hd + ".__loadUserManhourCallback", "text");
        _userkey = _url = null;
        __startLoading();
    }
    this.__loadUserManhourCallback = function (json) {
        __ajax = null;
        __endLoading();
        try {
            eval("__manHourData = " + json + ";");
        } catch (e) {
            //alert(json);
            __msgFunc("Data Parsing Error:<br/>" + e.message);
            return;
        }
        if (__manHourData[0] == 0) {
            __msgFunc(__manHourData[1]);
            return;
        }
        __showUserManhourList();
    };
    var __showUserManhourList = function () {
        var _str = new Array();
        if (__manHourData == null) {
            _str.push("no data");
        } else {
            var _item = null;
            var _sum = 0;
            _str.push('<table cellspacing="0" cellpadding="0" class="manhour_gridview" >');
            _str.push('<thead>');
            _str.push('<tr><td></td><td>查看项</td><td></td><td>工时</td></tr>');
            _str.push('</thead>');
            _str.push('<tbody>');
            for (var i = 0; i < __manHourData.length; i++) {
                _item = __manHourData[i];
                if (_item.UserKey != '') {
                    if (parseFloat(_item.CostHours) == 0) {
                        _str.push('<tr class="row_empty">');
                    } else if (parseFloat(_item.CostHours) < 8) {
                        _str.push('<tr class="row_low">');
                    } else {
                        _str.push('<tr class="row_normal">');
                    }
                } else {
                    _str.push('<tr class="row">');
                }
                _str.push('<td>' + (i + 1) + '</td>');
                if (_item.UserKey != '') {
                    _str.push('<td><a href="javascript:' + __hd + '.switchUser(\'' + _item.UserKey + '\',\'' + _item.ItemName + '\');">' + _item.ItemName + '</a></td>');
                } else {
                    _str.push('<td>' + _item.ItemName + '</td>');
                }
                _str.push('<td>' + _item.Project + '</td>');
                if (parseFloat(_item.CostHours) == 0) {
                    _str.push('<td class="ch_empty">' + _item.CostHours + '</td>');
                } else if (parseFloat(_item.CostHours) < 8) {
                    _str.push('<td class="ch_warning">' + _item.CostHours + '</td>');
                } else {
                    _str.push('<td class="ch_ok">' + _item.CostHours + '</td>');
                }
                _str.push('</tr>');
                _sum += parseFloat(_item.CostHours);
            }
            _str.push('</tbody>');
            _str.push('<tfoot>');
            _str.push('<tr><td colspan="3">合计</td><td>' + _sum + '</td></tr>');
            _str.push('</tfoot>');
            _str.push('</table>');
            _item = null;
        }
        __listBox.innerHTML = _str.join('');
        _str = null;
    };
    this.loadManhourList = function (rUserKey) {
        __listBox.innerHTML = "";
        __loadUserManhour(rUserKey);
    };
    /*  END: 用户工时查看 --------------------*/
    /*  BEGIN: 月历  ---------------------*/
    var __monthData = null;
    var __calendarInfoBox = null;
    var __loadMonthData = function () {
        var _url = "Ws/_Todo.aspx?act=71&dt=" + __datetime.toString("yyyy-MM-dd") + "&uid=" + __userId + "&rm=" + jskitUtil.guid();
        __ajax = new JskitXmlHttpAction(_url, __hd + ".__loadMonthDataCallback", "text");
        _userkey = _url = null;
        __startLoading();
    };
    this.__loadMonthDataCallback = function (json) {
        __ajax = null;
        __endLoading();
        try {
            eval("__monthData = " + json + ";");
        } catch (e) {
            json
            //alert(json);
            __msgFunc("Data Parsing Error:<br/>" + e.message);
            return;
        }
        if (__monthData[0] == 0) {
            __msgFunc(__monthData[1]);
            return;
        }
        __fillCalendar();
    };
    var __calJc = null;
    this.onCalJcDateChange = function (rDtStr) {
        if (__currentOperatorId == __userId) {
            window.location.href = "Default.aspx?dt=" + rDtStr;
        } else {
            window.location.href = "CheckUser.aspx?uid=" + __userId + "&dt=" + rDtStr;
        }
    };
    this.loadCalJc = function () {
        return __calJc;
    }
    var __fillCalendar = function () {
        if (__monthData.Checked == 1) {
            __calendarInfoBox.innerHTML = "本月已结";
        } else {
            __calendarInfoBox.innerHTML = "";
        }
        var _content = null;
        var _css = null;
        var _item = null;
        for (var i = 0; i < __monthData.Data.length; i++) {
            _item = __monthData.Data[i];
            if (_item.Weekend == 1) {
                _css = "mark_in_calendar_weekend";
            } else if (parseFloat(_item.CostHours) < 8) {
                _css = "mark_in_calendar_low";
            } else {
                _css = "mark_in_calendar";
            }
            _content = '<div class="' + _css + '">' + _item.CostHours + 'H</div>';
            __calJc.markIn(_item.TheDay, _content);
        }
        _item = _css = _content = null;
    };
    this.showCalendar = function () {
        __listBox.innerHTML = "";
        __calJc.setMode("d");
        __calJc.setDate(__datetime);
        __listBox.innerHTML = __calJc.getCalendarBodyHTML();
        __loadMonthData();
    };
    this.setCalendarInfoBox = function (v) {
        __calendarInfoBox = $("#" + v);
    };
    this.init4Calendar = function () {
        __calJc = new JskitDateSelector(__hd + ".loadCalJc()");
        __calJc.setSelectedHandler(__hd + ".onCalJcDateChange");
        __calJc.setCanvasCssClass("cal_canvasCssClass");
        __calJc.setCalendarTitleCssClass("cal_titleCssClass");
        __calJc.setTableCssClass("cal_tableCssClass");
        __calJc.setTHeadCssClass("cal_theadCssClass");
        __calJc.setTBodyCssClass("cal_tbodyCssClass");
        __calJc.setWeekendCssClass("cal_weekend");
        __calJc.setTodayCssClass("cal_today");
        __calJc.setDefaultMark('<div class="mark_in_calendar_empty">0H</div>');
        __calJc.setAutoCallback(false);
        __calendarInfoBox = $("#calendarInfo");
    };
    /*  BEGIN: 月结  --------------------*/

    /*  END: 月结  --------------------*/
    /*  END: 月历  --------------------*/
    /* BEGIN: 按月审查每天所有人录入的总工时数 ---------------------*/
    var __superviseData = null;
    this.loadSupervise = function () {
        __loadSuperviseData();
    };
    //0:1-10,1:11-20,3:21-max
    var __superviseGroup = null;
    var __loadSuperviseData = function () {
        var _url = "Ws/_Todo.aspx?act=99&dt=" + __datetime.toString("yyyy-MM-dd") + "&rm=" + jskitUtil.guid();
        __ajax = new JskitXmlHttpAction(_url, __hd + ".__loadSuperviseDataCallback", "text");
        _userkey = _url = null;
        __startLoading();
    }
    this.__loadSuperviseDataCallback = function (json) {
        __ajax = null;
        __endLoading();
        try {
            eval("__superviseData = " + json + ";");
        } catch (e) {
            //alert(json);
            __msgFunc("Data Parsing Error:<br/>" + e.message);
            return;
        }
        if (__superviseData[0] == 0) {
            __msgFunc(__superviseData[1]);
            return;
        }
        __showSuperviseDataList();
    };
    this.loadSuperviseGroup = function (rIdx) {
        __superviseGroup = parseInt(rIdx);
        __listBox.innerHTML = "";
        __showSuperviseDataList();
    };
    var __isWeekend = function (rDtStr) {
        var _dt = jskitUtil.date.parse(rDtStr);
        return (_dt.getDay() == 0 || _dt.getDay() == 6);
    };
    var __showSuperviseDataList = function () {
        var _str = new Array();
        var _curDay = __datetime.getDate();
        if (__superviseGroup == null) {
            if (_curDay <= 10) {
                __superviseGroup = 0;
            } else if (_curDay > 10 && _curDay <= 20) {
                __superviseGroup = 1;
            } else {
                __superviseGroup = 2;
            }
        }
        _curDay = null;
        var _colCount = __superviseData[0].length;
        var _dayCount = _colCount - 2;
        var _minDay = __superviseGroup * 10 + 1;
        var _maxDay = _minDay + 10;
        if (_maxDay > _dayCount) { _maxDay = _dayCount; }
        _str.push('<div class="tab_group">');
        if (__superviseGroup == 0) {
            _str.push('1日-11日');
            _str.push('&nbsp;|&nbsp;&nbsp;<a href="javascript:' + __hd + '.loadSuperviseGroup(1)">11日-21日</a>');
            _str.push('&nbsp;|&nbsp;&nbsp;<a href="javascript:' + __hd + '.loadSuperviseGroup(2)">21日-' + _dayCount + '日</a>');
        } else if (__superviseGroup == 1) {
            _str.push('<a href="javascript:' + __hd + '.loadSuperviseGroup(0)">1日-11日</a>');
            _str.push('&nbsp;|&nbsp;&nbsp;11日-21日');
            _str.push('&nbsp;|&nbsp;&nbsp;<a href="javascript:' + __hd + '.loadSuperviseGroup(2)">21日-' + _dayCount + '日</a>');
        } else if (__superviseGroup == 2) {
            _str.push('<a href="javascript:' + __hd + '.loadSuperviseGroup(0)">1日-11日</a>');
            _str.push('&nbsp;|&nbsp;&nbsp;<a href="javascript:' + __hd + '.loadSuperviseGroup(1)">11日-21日</a>');
            _str.push('&nbsp;|&nbsp;&nbsp;21日-' + _dayCount + '日');
        }
        _str.push('</div>');


        _str.push('<table cellspacing="0" cellpadding="0">');
        _str.push('<thead>');
        _str.push('<tr>');
        _str.push('<td class="col_user"><div>USER\\DAY</div></td>');
        for (var i = _minDay; i <= _maxDay; i++) {
            if (__isWeekend(__datetime.toString("yyyy-M-") + i)) {
                _str.push('<td><div class="weekend">' + i + '</div></td>');
            } else {
                _str.push('<td><div>' + i + '</div></td>');
            }
        }
        _str.push('</tr>');
        _str.push('</thead>');
        _str.push('<tbody>');
        var _rowCount = __superviseData.length;
        var _cost = null;
        for (var i = 0; i < _rowCount; i++) {
            _str.push('<tr class="row_normal">');
            _str.push('<th><div onclick="' + __hd + '.onSuperviseSelectRow(this,event)">' + __superviseData[i][1] + '</div></th>');
            for (var j = _minDay; j <= _maxDay; j++) {
                _cost = parseFloat(__superviseData[i][j + 1]);
                if (isNaN(_cost)) {
                    _cost = 0;
                } else {

                }
                if (_cost == 0) {
                    _str.push('<td class="c_empty" ');
                } else if (_cost < 8) {
                    _str.push('<td class="c_warning" ');
                    _str.push(' onclick="' + __hd + '.onSuperviseClick(' + i + ',' + (j + 1) + ')" ');
                } else {
                    _str.push('<td class="c_ok" ');
                    _str.push(' onclick="' + __hd + '.onSuperviseClick(' + i + ',' + (j + 1) + ')" ');
                }
                _str.push(' >' + _cost + '</td>');
            }
            _str.push('</tr>');
        }
        _str.push('</tbody>');
        _str.push('</table>');
        __listBox.innerHTML = _str.join('');
    };
    var __selectedRow = null;
    this.onSuperviseSelectRow = function (sender, event) {
        if (__selectedRow != null) {
            __selectedRow.className = "row_normal";
        }
        __selectedRow = sender.parentNode.parentNode;
        __selectedRow.className = "row_active";
    };
    this.onSuperviseClick = function (row, col) {
        window.location.href = "CheckUser.aspx?uid=" + encodeURI(__superviseData[row][0]) 
            + "&un=" + encodeURI(__superviseData[row][1])
            + "&dt=" + __datetime.toString("yyyy-M-") + col;
        _userKey = null;
    };
    /* END: 按月审查每天所有人录入的总工时数 ---------------------*/


    /* BEGIN: TAB Action ---------------------*/
    this.loadData = function () {
        __loadData();
    };
    /* END: TAB Action ---------------------*/
    this.getItemSelectorHd = function () {
        return __itemSelectorHd;
    };
    this.getUserSelectorHd = function () {
        return __userSelectorHd;
    };
    this.popupBrowser = function () {
        __popupBrowser();
    };
    this.setCurrentOperatorId = function (v) {
        __currentOperatorId = v;
    };

    this.updateDatetime = function (v) {
        if (v != null && v != '' && typeof (v) == "string") {
            __datetime = jskitUtil.date.parse(v);
            if (__datetime != null) {
                jDateSelector.setDate(__datetime);
            }
        }
        this.showDateInfo();
    };
    this.setDatePanel = function (rPanelId) {
        __datePanel = $("#" + rPanelId);
    };
    var __WeekText = ["日", "一", "二", "三", "四", "五", "六"];
    this.showDateInfo = function () {
        if (__datetime == null) { return; }
        __jc.lunar.parseDate(__datetime);
        if (__datePanel != null) {
            var _info = null;
            if (jDateSelector.getMode() == "m") {
                _info = __datetime.toString("yyyy年MM月");
                _info += "," + __jc.lunar.date["GanzhiYear"] + "年" + __jc.lunar.date["MonthText"];
                __datePanel.innerHTML = _info;
            } else {
                _info = __datetime.toString("yyyy年MM月dd日") + ",星期" + __WeekText[__datetime.getDay()];
                _info += "," + __jc.lunar.date["GanzhiYear"] + "年" + __jc.lunar.date["MonthText"] + __jc.lunar.date["DayText"];
                if (__jc.lunar.date["SolarTerm"] != "") {
                    _info += "," + __jc.lunar.date["SolarTerm"];
                }
                if (__datetime.toString("yyyyMMdd") == (new Date()).toString("yyyyMMdd")) {
                    __datePanel.innerHTML = "今日(" + _info + ")";
                } else {
                    __datePanel.innerHTML = _info;
                }
            }
            _info = null;
        }
    };
    /*-----------------------------*/
    this.deploy = function (rListBoxId) {
        __detailBoxId = __hd + "_detail";
        __detailBox = document.createElement("div");
        __detailBox.id = __detailBoxId;
        __detailBox.className = "detail_box";
        __detailBox.style.display = "none";
        __detailBox.style.position = "absolute";
        __detailBox.style.zIndex = 10;
        $("body").appendChild(__detailBox);

        __formBoxId = __hd + "_form";
        __formBox = document.createElement("div");
        __formBox.id = __formBoxId;
        __formBox.className = "form_box";
        __formBox.style.display = "none";
        __formBox.style.position = "absolute";
        __formBox.style.zIndex = 10;
        $("body").appendChild(__formBox);

        __loadingBoxId = __hd + "_loading";
        __loadingBox = document.createElement("div");
        __loadingBox.id = __loadingBoxId;
        __loadingBox.className = "loading_box";
        __loadingBox.style.display = "none";
        __loadingBox.style.position = "absolute";
        __loadingBox.style.zIndex = 10;
        $("body").appendChild(__loadingBox);

        __listBox = $("#" + rListBoxId);
        this.showDateInfo();

        __itemSelectorHd = new JskitRichDropDownList(__hd + ".getItemSelectorHd()");
        __userSelectorHd = new JskitRichDropDownList(__hd + ".getUserSelectorHd()");

        jskitEvents.add(__detailBox, "ondblclick", __hd + ".CloseDetails");
        __initFormBox();
        if (__alertIntervalMinutes != null) {
            __alertTimer = window.setInterval(__hd + ".AlertCheck", (__alertIntervalMinutes * 60) * 1000);
        }
    };
};